package com.grgbanking.it.common.mail;

import com.grgbanking.it.common.Constant;
import com.grgbanking.it.common.Message;

/**
 * 邮件工具
 * @author pgwei
 *
 */
public class MailUtil {
	private static MailUtil common = new MailUtil();
	
	public static MailUtil getInstance(){
		return common;
	}
	
	private MailInfo getSentConfig(){
		MailInfo mailInfo = new MailInfo();
		mailInfo.setMailServerHost("smtp.grgbanking.com");
		mailInfo.setMailServerPort("25");
		mailInfo.setValidate(true);
		mailInfo.setUserName("itms@grgbanking.com");
		mailInfo.setPassword("grg2014");// 您的邮箱密码
		mailInfo.setFromAddress("itms@grgbanking.com");
		
		return mailInfo;
	}
	
	public void sent(String email,String header,String content){
		MailInfo mailInfo = getSentConfig();
		mailInfo.setToAddress(email);
		mailInfo.setSubject(header);
		mailInfo.setContent(content);
		SimpleMailSender.sendTextMail(mailInfo);
	}
	
	/**
	 * 当工作创建的时候发送
	 * @param email
	 */
	public void sentWhenWorkCreated(String email){
		String header = Constant.WORK_MAIL_TITLE;
		String content = Message.WORK_CREATED;
		
		sent(email, header, content);
	}
	
	/**
	 * 当工作完成的时候发送
	 * @param email
	 */
	public void sentWhenWorkFinished(String email){
		String header = Constant.WORK_MAIL_TITLE;
		String content = Message.WORK_FINISHED;
		
		sent(email, header, content);
	}
}
